﻿class PaintPlayer extends PlayerBase {
    public play(): void {
        /*
        if (this.snd) {
            this.snd.play();
            this.snd.addEventListener(egret.SoundEvent.SOUND_COMPLETE, this.finish, this);
        }
        */
        /*
            GlobalAudio.play(this.audio,() => {
                this.onSndComp();
            });
        */
        if (this.paint.audio)
            SoundManager.playSound(QNService.getFullUrl(this.paint.audio), ()=>this.finish());
    }

    public stop(): void {
    }

    public pause(): void {
    }

    public resume(): void {
    }

    public initData(obj: PaintLoader): void {
        super.initData(obj);
        var cover: egret.Bitmap = new egret.Bitmap(this.getRes(this.paint.cover));
        cover.width = 1024;
        cover.height = 768;
        this.addChild(cover);

        /*if (this.paint.audio)
            this.snd = this.getRes(this.paint.audio);
        */
        this.play();
    }

    public finish(): void {
        this.dispatchEvent(new egret.Event(egret.Event.COMPLETE));
    }

    //private snd: egret.Sound;

    public dispose(): void {
        //GlobalAudio.stop();
        /*if (this.snd) {
            this.snd.removeEventListener(egret.SoundEvent.SOUND_COMPLETE, this.finish, this);
            this.snd.stop();
        }*/
        SoundManager.stopSound();
    }
}